home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Tools / Languages / Icon 8.1 / mep1 / External Functions / Samples / testcset.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-11-24  |  2.5 KB  |  81 lines  |  [TEXT/KAHL]

  1. /*
  2.  * Test writing an external function for ProIcon
  3.  *
  4.  * This code resource will appear under the resource type 'TEST', ID 1002,
  5.  * name "Cset Test".  Invoke with:
  6.  *
  7.  *      callout("TEST", "Cset Test", int1, int2)
  8.  *
  9.  * It accepts two integer arguments and returns the cset spanning those character codes.
  10.  */
  11.  
  12.  
  13. #include "ProIcon.h"
  14.  
  15. /*
  16.  * Code resource called as:
  17.  *   callout("type", "resource name", ...)
  18.  * where:
  19.  *  "type" is a Macintosh 4-character resource type code
  20.  *  "resource name" is a string used to specify resource by name.
  21.  *  ... are additional arguments whose dptrs are pushed on the stack.
  22.  *
  23.  * dargv[0]      - Arg0 - descriptor to place result
  24.  * dargv[1]      - Arg1 - first user argument
  25.  * dargv[argc]   - Argn - last user argument
  26.  * ip            - pointer to integer used to signal error.  *ip is initialized
  27.  *                 to -1, signifying no error.
  28.  *
  29.  * Possible returns:
  30.  *   Success     - Leave *ip unaltered, return descriptor pointer.
  31.  *   Failure     - Leave *ip unaltered, return NULL.
  32.  *   Error       - Set *ip to error code >= 0.  Return descriptor pointer or NULL
  33.  *                 to have value displayed or not displayed in error message.
  34.  */
  35.  
  36. pascal dptr main(dargv, argc, ip, callback)
  37. struct descrip dargv[];
  38. short int argc;
  39. short int *ip;
  40. pointer (*callback)();
  41. {
  42.    register struct b_cset *bp;
  43.    word i1, i2;
  44.    short int j;
  45.  
  46.    if (argc != 2)                        /* fail if wrong number of arguments */
  47.       Fail;
  48.  
  49.    if (Type(Arg1) != T_Integer)
  50.       RunErr(Err101, &Arg1);            /* integer expected for first user arg */
  51.  
  52.    if (Type(Arg2) != T_Integer)
  53.       RunErr(Err101, &Arg2);            /* integer expected for second user arg */
  54.    
  55.    if ((i1 = IntVal(Arg1)) < 0 || i1 >= 256)
  56.       RunErr(Err205, &Arg1);            /* first argument out of range */
  57.  
  58.    if ((i2 = IntVal(Arg2)) < 0 || i2 >= 256 || i2 < i1)
  59.       RunErr(Err205, &Arg2);            /* second argument out of range */
  60.  
  61.    if (blkreq((word)sizeof(struct b_cset)) == Error) /* notify ProIcon of memory needs */
  62.       RunErr(0, NULL);
  63.  
  64.    bp = alccset();                        /* allocate block for cset */
  65.    ArgType(0) = D_Cset;                    /* set cset result code */
  66.    BlkLoc(Arg0) = (union block *) bp;    /* point to block containing cset */
  67.    bp->size = i2 - i1 + 1;                /* number of bits on */
  68.    while (i1 <= i2) {
  69.       if (CsetOff(i1) == 0 && i1 + IntBits <= i2) {
  70.          *CsetPtr(i1,bp->bits) = MaxUnsigned;    /* word at a time */
  71.          i1 += IntBits;
  72.          }
  73.       else {
  74.          Setb(i1, bp->bits);            /* bit by bit */
  75.          i1++;
  76.          }
  77.       }
  78.  
  79.    Return;
  80. }
  81.